package com.ling.service;

import com.ling.bean.AnswerComment;
import com.ling.bean.AnswerCommentExample;
import com.ling.dao.AnswerCommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AnswerCommentService {

    private final AnswerCommentMapper answerCommentMapper;

    @Autowired
    public AnswerCommentService(AnswerCommentMapper answerCommentMapper) {
        this.answerCommentMapper = answerCommentMapper;
    }

    //获取指定回答的评论数据
    public List<AnswerComment> getAnswerCommentByAnswerId(String answerId) {
        AnswerCommentExample answerCommentExample = new AnswerCommentExample();
        //按照评论时间，正序排序
        answerCommentExample.setOrderByClause("editTime ASC");
        answerCommentExample.createCriteria().andAnsweridEqualTo(answerId);
        return answerCommentMapper.selectByExample(answerCommentExample);
    }

    //添加评论
    public void addAnswerComment(AnswerComment answerComment) {
        answerCommentMapper.insertSelective(answerComment);
    }
}
